<?php
declare(strict_types=1);

namespace app\model;

use think\Model;

class UserBalanceFlow extends Model
{
    protected $autoWriteTimestamp = true;

    // 类型常量
    const TYPE_RECHARGE = 1; // 充值
    const TYPE_WITHDRAW = 2; // 提现
    const TYPE_ORDER_PAY = 3; // 订单支付
    const TYPE_ORDER_REFUND = 4; // 订单退款
    const TYPE_COMMISSION = 5; // 分佣
    const TYPE_ORDER_CANCEL = 6; // 订单取消

    // 类型文字说明
    public static $typeTexts = [
        self::TYPE_RECHARGE => '充值',
        self::TYPE_WITHDRAW => '提现',
        self::TYPE_ORDER_PAY => '订单支付',
        self::TYPE_ORDER_REFUND => '订单退款',
        self::TYPE_COMMISSION => '分佣',
        self::TYPE_ORDER_CANCEL => '订单取消'
    ];

    // 关联用户
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    // 获取类型文字
    public function getTypeTextAttr()
    {
        return self::$typeTexts[$this->type] ?? '未知';
    }
} 